<?php

namespace IDock\Insurance\JTIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDock;
use IDock\IDock\IDockEnums;
use IDock\Insurance\JTIC\JTICEnums;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends AllJTICResponse
{

    /*** @var VehicleModelPrinter $printer */
    public $printer = VehicleModelPrinter::class;

    public function printerInit(): Response
    {
        $vehicleModelList = $this->get('VehicleModelList',[])['VehicleModelItem'] ?? [];
        if(empty($vehicleModelList)){
            return $this;
        }
        if (!key_exists(0,$vehicleModelList)) {
            $tmp = $vehicleModelList;
            unset($vehicleModelList);
            $vehicleModelList[] = $tmp;
        }

        foreach ($vehicleModelList as $vehicleMode) {
            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $vehicleMode['VehicleId'] ?? '';
            $vehiclePrinter->vehicleName = $vehicleMode['VehicleName'] ?? '';
            $vehiclePrinter->vehicleExhaust = $vehicleMode['VehicleExhaust'] ?? '';
            $vehiclePrinter->vehicleSeat = $vehicleMode['VehicleSeat'] ?? '';
            $vehiclePrinter->vehicleTonnage = ($vehicleMode['VehicleTonnage'] ?? '') ? (string)($vehicleMode['VehicleTonnage'] * 1000) : '0';
            $vehiclePrinter->vehiclePrice = $vehicleMode['VehiclePrice'] ?? '';
            $vehiclePrinter->vehiclePriceWithOutTax = $vehicleMode['VehiclePrice'] ?? '';
            $vehiclePrinter->isNewEnergy = $vehicleMode['NewEnergy'] ?? '0';
            $vehiclePrinter->remark = $vehicleMode['VehicleAlias'] ?? '';
            $vehiclePrinter->brandName = $vehicleMode['BrandName'] ?? '';
            $vehiclePrinter->familyName = $vehicleMode['FamilyName'] ?? '';
            $vehiclePrinter->wholeWeight = $vehicleMode['QualityMax'] ?? '';
            $vehiclePrinter->power = '';
            $vehiclePrinter->vehicleYear = $vehicleMode['MarketaDate'] ?? '';
            $vehiclePrinter->energyTypeCode = 'E01';
            $vehiclePrinter->energyTypeName = IDockEnums::$energyType[$vehiclePrinter->energyTypeCode];

            $vehiclePrinter->vehicleImportName = $vehicleMode['VehicleType'] ?? '';
            $vehiclePrinter->vehicleImport =  JTICEnums::$importFlagReverse[$vehiclePrinter->vehicleImportName] ?? '';
            $vehiclePrinter->item['ModelCode'] = $vehicleMode['ModelCode'] ?? '';
            $this->printer->setModelList($vehiclePrinter);
        }

        return $this;
    }
}
